# Maintainer: Manuel Naranjo <naranjo.manuel@gmail.com>

_pyname=psutil
_realname=${_pyname}
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=5.6.7
pkgrel=1
pkgdesc="A cross-platform process and system utilities module for Python (mingw-w64)"
arch=('any')
url="https://github.com/giampaolo/psutil"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('staticlibs' 'strip' '!debug')
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/giampaolo/psutil/archive/release-${pkgver}.tar.gz"
        '0001-MSYS-Allow-detecting-when-running-on-MSYS.patch'
        '0002-msys-fixes-for-msys2.patch')
sha256sums=('ebbed18bf912fa4981d05c5c1a0cacec2aa8c594e1608f0cf5cc7a3d4f63d4d4'
            'd3a325e2a073f23e5a6e9ce15e371e0c113af07942deb57e05b7185bc2407d4a'
            'b5dadc659509fa07b3333eb235f8a43511bd01acbb16c36f840ff61ef0ede834')

prepare() {
  cd "${srcdir}"/${_realname}-release-${pkgver}
  patch -p1 -i "${srcdir}/0001-MSYS-Allow-detecting-when-running-on-MSYS.patch"
  patch -p1 -i "${srcdir}/0002-msys-fixes-for-msys2.patch"

  cd ${srcdir}
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-release-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python test for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  msg "Python test for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py check
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING"
}
